#ifndef ROEXPORT_PROPERTY_H
#define ROEXPORT_PROPERTY_H

#include "ROSharedObject.h"

//用于指定一个目标对象，将目标对象的属性进行链接，服务端的目标对象属性改变后会传递给客户端的目标对象
//注意，properties属性中不能出现"target"和"properties"属性

class ROExportProperty:public ROSharedObject
{
    Q_OBJECT
    QML_NAMED_ELEMENT(ROExportProperty)
public:
    ROExportProperty(QObject* parent = nullptr);
    QObject *target() const;
    void setTarget(QObject *newTarget);

    QStringList properties() const;
    void setProperties(const QStringList &newProperties);

signals:
    void targetChanged();

    void propertiesChanged();

protected:
    void initialize() override;
    QStringList allProperties() override;
    QVariantMap extractProperties(const QStringList& prop) override;
    void handleProperties(const QVariantMap& var) override;

private:

    QObject* m_target = nullptr;
    QObject* m_ckeeper = nullptr;
    QStringList m_properties;
    void validate();
    Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged FINAL)
    Q_PROPERTY(QStringList properties READ properties WRITE setProperties NOTIFY propertiesChanged FINAL)
};

class SharedProperty:public QObject{
    Q_OBJECT
    QML_ELEMENT
    QML_ATTACHED(ROExportProperty)
    QML_UNCREATABLE("")
public:
    static ROExportProperty* qmlAttachedProperties(QObject* object);
};

#endif
